package com.onlineClass.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author helen
 * @since 2019/6/22
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
	@Override
	public void insertFill(MetaObject metaObject) {

		log.info("插入时自动填充......");
		/*createTime是实体类中的属性名称，填充内容（类型和属性一致），*/
		this.setFieldValByName("createTime", new Date(), metaObject);
		this.setFieldValByName("updateTime", new Date(), metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {

		log.info("更新时自动填充......");
		this.setFieldValByName("updateTime", new Date(), metaObject);
	}
}
